package net.lzzy.practices;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * @author
 */
@Component

public class PracticesMvcConfigurer  implements WebMvcConfigurer {
    @Value("${user.pic}")
    private String picPath;
    @Value("${pic.size}")
    private int maxPicSize;

    @Bean
    public CommonsMultipartResolver multipartResolver(){
        CommonsMultipartResolver resolver =new CommonsMultipartResolver();
        resolver.setMaxUploadSize(maxPicSize);
        return resolver;
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**")
                .addResourceLocations("file:/"+picPath,"classpath:/webapp/","classpath:/static/","classpath:/public/");
        //通过配置URL规则查找我的位置 spring MVC在处理静态资源请求时，按照指定的路径规则从这些位置查找资源文件，提供正确的静态资源访问和服务（图片，脚本，页面）
    }
}
